package wn.lizzy.thread.singleton;

final class EagerSingleton {
	private static EagerSingleton instance = new EagerSingleton();

	private EagerSingleton() {
		
	}

	public static EagerSingleton getSingleInstance() {
		return instance;
	}
}


final class LazySingleton {
	private static LazySingleton instance = null;

	private LazySingleton() {
	}

	public static LazySingleton getSingleInstance() {
		if (null == instance) {
			instance = new LazySingleton();
		}
		return instance;
	}
}


final class LazySingletonNew {
	private static LazySingletonNew instance = null;

	private LazySingletonNew() {
	}

	public static synchronized LazySingletonNew getSingleInstance() {
		if (null == instance) {
			instance = new LazySingletonNew();
		}
		return instance;
	}
}


final class DoubleCheckedSingleton {    
    private static DoubleCheckedSingleton instance = null;    
        
    private DoubleCheckedSingleton(){    
    }    

    public static DoubleCheckedSingleton getSingleInstance(){    
        if(instance == null ) {  
        	synchronized(DoubleCheckedSingleton.class){  
                if(instance == null){  
                	instance = new DoubleCheckedSingleton();  
            }  
        }  
    }  
    return instance;
    }    
}    

public class Singleton {      
    private static class SingletonHolder {      
        public final static Singleton instance = new Singleton();      
    }      
         
    public static Singleton getInstance() {      
        return SingletonHolder.instance;      
    }      
}    
